package main

import (
	"github.com/gin-gonic/gin"
	"html/template"
)

func main() {
	r := gin.Default()
	r.SetFuncMap(template.FuncMap{
		"safe": func(str string) template.HTML {
			return template.HTML(str)
		},
	})
	//r.LoadHTMLFiles("templates/index.tmpl") //解析一个模板文件
	r.LoadHTMLGlob("templates/**/*") //模板解析,将template下所有子文件夹及下所有文件都解析

	//Http Get请求
	r.GET("/posts/index", func(c *gin.Context) {
		c.HTML(200, "index.tmpl", gin.H{ //模板渲染
			"title": "post/title",
			//"url":   "http: //www.163.com",
		})
	})

	r.GET("/users/index", func(c *gin.Context) {
		c.HTML(200, "index.tmpl", gin.H{ //模板渲染
			"title": "user/title",
			"url":   "<a href='http://www.163.com'>163</a>",
		})
	})
	r.Run(":9000") //启动server
}
